﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using cmdb.keede.common;
using cmdb.keede.entity;
using cmdb.keede.service;
using cmdb.keede.service.Contract;
using Microsoft.AspNetCore.Mvc;

namespace cmdb.keede.com.Controllers
{
    public class GroupController : Controller
    {
        readonly IGroupService _groupService;

        public GroupController(IGroupService groupService)
        {
            _groupService = groupService;
        }

        public IActionResult Index()
        {
            return View();
        }

        public async Task<BizResult<List<Group>>> GetGroupes(int pageIndex, int pageSize)
        {
            return await _groupService.GetGroupesAsync(pageIndex, pageSize);
        }

        public async Task<BizResult<Group>> GetGroup(int id)
        {
            return await _groupService.GetGroupAsync(id);
        }

        public async Task<BizResult<bool>> DeleteGroup(int id)
        {
            return await _groupService.DeleteGroupAsync(id);
        }

        [HttpPost]
        public async Task<BizResult<bool>> AddOrUpdateGroupX(GroupRequest request)
        {
            return await _groupService.AddOrUpdateAppInfoAsync(request);
        }

        [HttpPost]
        public async Task<BizResult<bool>> AddOrUpdateGroup(Group group)
        {
            return await _groupService.AddOrUpdateAppInfoAsync(group);
        }
    }
}